package com.ljt.service.impl;

import com.ljt.dao.UserMapper;
import com.ljt.pojo.User;
import com.ljt.pojo.UserExample;
import com.ljt.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public User login(String username, String password) {
        UserExample example = new UserExample();
        //设置查询条件
        UserExample.Criteria criteria = example.createCriteria();
        criteria.andUsernameEqualTo(username);
        criteria.andPasswordEqualTo(password);

        List<User> list = userMapper.selectByExample(example);
        //等价于select * from user where username=? and password=?
        if(list!=null&&list.size()>0){
            return list.get(0);
        }
        return null;
    }


    @Override
    public List<User> select(){
        return userMapper.select();
    }

    @Override
    public User selectByUsername(String username){
        return userMapper.selectByUsername(username);
    }

}